local lishuo = fk.CreateSkill{
  name = "wk_heg__lishuo",
}

Fk:loadTranslationTable{
  ["wk_heg__lishuo"] = "礼朔",
  [":wk_heg__lishuo"] = "当你受到伤害后，你可令一名角色弃置其装备区内一种颜色的所有牌，然后若其以此法弃置的牌颜色为：红色，其回复1点体力；黑色，其将手牌调整至体力上限。",
  ["#wk_heg__lishuo-ask"] = "礼朔：选择一名装备区内有牌的角色，令其弃置装备区内一种颜色所有牌并执行对应效果",
  ["wk_heg__lishuo_discard"] = "礼朔：选择弃置装备区内黑色或红色的所有牌，黑色调整手牌，红色回复体力",
  ["wk_heg__lishuo_black"] = "黑色",
  ["wk_heg__lishuo_red"] = "红色",
}

lishuo:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and player == target
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room.alive_players, function (p) return #p:getCardIds("e") > 0 end)
    local tos = room:askToChoosePlayers(player,{
      targets = targets,
      min_num = 1,
      max_num = 1,
      prompt = "#wk_heg__lishuo-ask",
      skill_name = lishuo.name,
      cancelable = true,
    })
    if #tos > 0 then
      event:setCostData(self, {tos = tos[1]})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos
    local cards = to:getCardIds(Player.Equip)
    local all_choices = {"wk_heg__lishuo_black", "wk_heg__lishuo_red"}
    local black = {}
    local red = {}
    for _, cid in ipairs(cards) do
      local card = Fk:getCardById(cid)
      if card.color == Card.Black then
        table.insertIfNeed(black, cid)
      end
      if card.color == Card.Red then
        table.insertIfNeed(red, cid)
      end
    end
    local choices = {}
    if #black > 0 then
      table.insert(choices, "wk_heg__lishuo_black")
    end
    if #red > 0 then
      table.insert(choices, "wk_heg__lishuo_red")
    end
    if #choices == 0 then return false end
    local choice = room:askToChoice(to, {
      choices = choices,
      skill_name = lishuo.name,
      prompt = "wk_heg__lishuo_discard",
      all_choices = all_choices,
    })
    if choice == "wk_heg__lishuo_black" then
      room:throwCard(black, lishuo.name, to, player)
      local dis = to:getHandcardNum() - to.maxHp
      if dis < 0 then
        to:drawCards(-dis, lishuo.name)
      elseif dis > 0 then
        room:askToDiscard(to,{
          min_num = dis,
          max_num = dis,
          include_equip = false,
          skill_name = lishuo.name,
          cancelable = false,
          skip = false,
        })
      end
    else
      room:throwCard(red, lishuo.name, to, player)
      if to.hp < to.maxHp then
        room:recover{
          who = to,
          num = 1,
          recoverBy = to,
          skillName = lishuo.name
        }
      end
    end
  end,
})

return lishuo